package 富婆梦.第一阶段.Java基础视频学习.线程的练习.练习;

/**
 * @ProjectName: java-learning
 * @Package: 富婆梦.第一阶段.线程的练习.练习
 * @ClassName: ThreadInterrupt
 * @Author: hemengjin
 * @Description: 测试线程的中止
 * @Date:2021/10/30 12:33
 * @Version: 1.0
 */
public class ThreadInterrupt extends Thread{
    public void run(){
        try {
            sleep(10000);
        }catch (InterruptedException e){
            System.out.println(e.getMessage());
        }
    }

    public static void main(String[] args) throws Exception{
        Thread thread = new ThreadInterrupt();
        thread.start();
        System.out.println("在50秒内按任意键中断线程！");
        System.in.read();
        thread.interrupt();
        thread.join();
        System.out.println("线程已经退出！");
    }
}
